<template id="motion">
  <div>
    <el-input style="width: 25%;" v-model="motionmc" placeholder="请输入名称"></el-input>
        &nbsp;&nbsp;
        <el-button style="width: 15%;" @click="queryAll" type="primary">查询</el-button>
        <el-button style="width: 15%;" @click="kk=true"  type="primary">添加</el-button>
        <el-table :data="list">
        <el-table-column prop="id" label="编号"> 
        </el-table-column>
        <el-table-column prop="motion" label="编码" width="140">
        </el-table-column>
        <el-table-column prop="motionmc" label="项目名称" width="120">
        </el-table-column>
        <el-table-column prop="motionintensity" label="运动强度">
        </el-table-column>
        <el-table-column prop="motiontime" label="运动时间">
        </el-table-column>
        <el-table-column prop="gender" label="适用性别">
          <template slot-scope="scope">
              {{ scope.row.gender==0?"不限"
                :scope.row.gender==1?"男":"女"
               }}
          </template>
        </el-table-column>
        <el-table-column prop="measure" label="千步当量">
        </el-table-column>
        <el-table-column prop="" label="年龄区间">
            <template slot-scope="scope">
                <span>
                    {{ scope.row.minage }}-{{ scope.row.maxage }}
                </span>
            </template>
        </el-table-column>
        <el-table-column prop="stretchpart" label="拉伸部位">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary"  icon="el-icon-edit" @click="queryId(scope.row.id),up=true"  circle></el-button>
            <el-popconfirm @confirm="del(scope.row.id)" title="确定删除此内容吗？">
            <el-button type="danger" slot="reference" icon="el-icon-delete" circle></el-button>
          </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[3, 5, 7, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <!--添加-->
    <el-dialog
    title="添加"
    :visible.sync="kk"
    width="30%"
    center>
    <el-form :model="motion" status-icon  ref="motion" label-width="100px" class="demo-ruleForm">
    项目名称:<el-input v-model="motion.motionmc" style="width: 80%;"/><br>
    <h1></h1>
    适用性别:<el-select v-model="motion.gender" style="width: 80%;">
      <el-option label="不限" value="0"></el-option>
      <el-option label="男" value="1"></el-option>
      <el-option label="女" value="2"></el-option>
    </el-select><br>
    <h1></h1>
    运动时间:<el-input v-model="motion.motiontime" style="width: 80%;"/><br>
    <h1></h1>
    运动强度:<el-input v-model="motion.motionintensity" style="width: 80%;"/><br>
    <h1></h1>
    年龄下限:<el-input v-model="motion.minage" style="width: 80%;"></el-input><br>
    <h1></h1>
    年龄上限:<el-input v-model="motion.maxage" style="width: 80%;"></el-input><br>
    <h1></h1>
    千步当量:<el-input v-model="motion.measure" style="width: 80%;"></el-input><br>
    <h1></h1>
    拉伸部位:<el-input v-model="motion.stretchpart" style="width: 80%;"></el-input><br>
    <h1></h1>
  
    <el-button @click="reset('motion'),kk = false">取 消</el-button>
    <el-button type="primary" @click="kk = false,add()" >确 定</el-button>
  </el-form>
  </el-dialog>

   <!--修改-->
   <el-dialog
    title="修改"
    :visible.sync="up"
    width="30%"
    center>
    
    <el-form :model="motions" status-icon  ref="motion" label-width="100px" class="demo-ruleForm">
      <input type="hidden" v-model="motions.id"/>
    项目名称:<el-input v-model="motions.motionmc" style="width: 80%;"/><br>
    <h1></h1>
    适用性别:<el-select v-model="motions.gender" placeholder="请选择性别" style="width: 80%;">
      <el-option label="不限" value="0"></el-option> 
      <el-option label="男" value="1"></el-option>
      <el-option label="女" value="2"></el-option>
    </el-select><br>
    <h1></h1>
    运动时间:<el-input v-model="motions.motiontime" style="width: 80%;"/><br>
    <h1></h1>
    运动强度:<el-input v-model="motions.motionintensity" style="width: 80%;"/><br>
    <h1></h1>
    年龄下限:<el-input v-model="motions.minage" style="width: 80%;"></el-input><br>
    <h1></h1>
    年龄上限:<el-input v-model="motions.maxage" style="width: 80%;"></el-input><br>
    <h1></h1>
    千步当量:<el-input v-model="motions.measure" style="width: 80%;"></el-input><br>
    <h1></h1>
    拉伸部位:<el-input v-model="motions.stretchpart" style="width: 80%;"></el-input><br>
    <h1></h1>
    <el-button @click="reset('motion'),up = false">取 消</el-button>
    <el-button type="primary" @click="up = false,update()" >修改</el-button>
  </el-form>
  </el-dialog>


  </div>
</template>

<script>
export default {
        data(){
            return{
                kk:false,
                up:false,
                total:10,
                pageSize:4,
                currentPage4:1,
                motionmc:"",
                list:[],
                motion:{motionmc:"",motionintensity:"",motiontime:"",maxage:"",measure:"",minage:"",gender:"",stretchpart:""},
                motions:{id:"",motionmc:"",motionintensity:"",motiontime:"",maxage:"",measure:"",minage:"",gender:"",stretchpart:""}
            }
        },
        methods:{
            queryAll(){
                this.axios.post("/tomcat/Z_motionAll",{page:this.currentPage4,num:this.pageSize,motionmc:this.motionmc})
                .then(s=>{
                    this.list=s.data.rows
                    this.total=s.data.total
                })
            },
            del(id){
              this.axios.get("/tomcat/Z_motionDel?id="+id).then(s=>{
                if(s.data>0){
                  this.$notify({
                      title: '成功',
                      message: '这是一条删除成功的提示消息',
                      position: 'top-left',
                      type: 'success'
                    });
                    this.queryAll();
                }
              })
            },
            update(){
              this.axios.post("/tomcat/Z_motionUp",{id:this.motions.id,motionmc:this.motions.motionmc,motionintensity:this.motions.motionintensity,
                motiontime:this.motions.motiontime,maxage:this.motions.maxage,minage:this.motions.minage,measure:this.motions.measure,
                gender:this.motions.gender,stretchpart:this.motions.stretchpart}).then(s=>{
                  if(s.data>0){
                    this.$notify({
                    title: '成功',
                    message: '这是一条修改成功的提示消息',
                    type: 'success'
                  });
                  this.queryAll();
                  }
                })

              
            },
            queryId(id){
              this.axios.post("/tomcat/Z_motionById",{id:id}).then(s=>{
                console.log(s.data)
                this.motions=s.data
              })
            },
            add(){
              this.axios.post("/tomcat/Z_motionAdd",{motionmc:this.motion.motionmc,motionintensity:this.motion.motionintensity,
                motiontime:this.motion.motiontime,maxage:this.motion.maxage,minage:this.motion.minage,measure:this.motion.measure,
                gender:this.motion.gender,stretchpart:this.motion.stretchpart}).then(s=>{
                  if(s.data>0){
                    this.$notify({
                    title: '成功',
                    message: '这是一条添加成功的提示消息',
                    type: 'success'
                  });
                  this.queryAll();
                  this.reset();
                  }
                })
            },
            handleSizeChange(val) {
            this.pageSize=val
            this.queryAll();
        
            },
            handleCurrentChange(val) {
                this.currentPage4=val
                this.queryAll();
            },
            reset(){
              this.motion={}
            }
            
        },
        created(){
            this.queryAll();
        }
}
</script>

<style>

</style>